﻿using DimensionsHelper.Common.Contracts.Services;
using Microsoft.Win32;

namespace DimensionsHelper.Client.Services;

public class FilePickerService : IFilePikerService
{
    public async Task<IReadOnlyList<string>> PickMultipleFilesAsync(params string[] typeFilters)
    {
        return await Task.Run<IReadOnlyList<string>>(() =>
        {
            OpenFileDialog openFileDialog = new()
            {
                Filter = string.Join('|', typeFilters),
                Multiselect = true
            };

            if (openFileDialog.ShowDialog() == true)
            {
                return openFileDialog.FileNames;
            }

            return [];
        });
    }

    public async Task<string?> PickSingleFileAsync(params string[] typeFilters)
    {
        return await Task.Run(() =>
        {
            OpenFileDialog openFileDialog = new()
            {
                Filter = string.Join('|', typeFilters)
            };

            if (openFileDialog.ShowDialog() == true)
            {
                return openFileDialog.FileName;
            }

            return null;
        });
    }


    public async Task<string?> SaveFileAsync(params string[] typeFilters)
    {
        return await Task.Run(() =>
        {
            SaveFileDialog saveFileDialog = new()
            {
                Filter = string.Join('|', typeFilters)
            };

            if (saveFileDialog.ShowDialog() == true)
            {
                return saveFileDialog.FileName;
            }

            return null;
        });
    }
}
